//
//  MessageModel.m
//  markmap
//
//  Created by 甘世清 on 2024/3/29.
//

#import "MessageModel.h"

@implementation MessageModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName{
   return @{@"iduser": @"id"};
}

-(CGSize)cellSize{
    CGSize size = [Manager SQ_boundingAttributedStringRectWithSize:CGSizeMake(SCREEN_WIDETH-16-48-10-48-16-10, MAXFLOAT) lineSpace:2 textFont:FONT_MEDIUM(15) string:self.content];
    CGFloat w = size.width + 14;
    if (w< 20) {
        w = 30;
    }
    UITextView * text = [[UITextView alloc]init];
    text.text = self.content;
    text.font = FONT_MEDIUM(15);

    return CGSizeMake(w, [text sizeThatFits:CGSizeMake(SCREEN_WIDETH-16-48-10-48-16-10, MAXFLOAT)].height + 6);
}




/**
 对数组里存放model的某个属性对数组进行重新排序

 @param array 待排序数组
 @param increase 是否增序排列
 @param key 属性
 @return <#return value description#>
 */
+(NSArray *)sortArray:(NSArray *)array increase:(BOOL)increase byKey:(NSString *)key{
    
    array = [array sortedArrayUsingComparator:
             ^NSComparisonResult(MessageModel *obj1, MessageModel *obj2) {
                 NSComparisonResult result;
                 if ([key isEqualToString:@"userId"]) {
                     CGFloat res1 = [[obj1 valueForKey:key] floatValue];
                     CGFloat res2 = [[obj2 valueForKey:key] floatValue];
                     if (increase) {
                         if (res1 < res2){
                             result = NSOrderedAscending;
                         }else {
                             result = NSOrderedDescending;
                         }
                     } else {
                         if (res1 < res2){
                             result = NSOrderedDescending;
                         }else {
                             result = NSOrderedAscending;
                         }
                     }
                 } else {
                     result = [[obj1 valueForKey:key] compare:[obj2 valueForKey:key]];
                     if (!increase) {
                         if (result == NSOrderedDescending) {
                             result = NSOrderedAscending;
                         } else if (result == NSOrderedAscending) {
                             result = NSOrderedDescending;
                         }
                     }
                 }
                 
                 return result;
             }].mutableCopy;
    return array;
}
@end
